using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using FireStarter.Base;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.Base.Exceptions;
using Habanero.BO;
using Habanero.Testability;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for DMInheritanceRelationship objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for DMInheritanceRelationship.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestDMInheritanceRelationship
    {
        [SetUp]
        public override void SetupTest()
        {
            //Runs every time that any testmethod is executed
            base.SetupTest();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.SetupFixture();
        }

        [TearDown]
        public override void TearDownTest()
        {
            //runs every time any testmethod is complete
            base.TearDownTest();
        }

        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmInheritanceRelationship.SubClass, "DMInheritanceRelationship.SubClass Should not be null");
            Assert.IsNotNull(dmInheritanceRelationship.SuperClass, "DMInheritanceRelationship.SuperClass Should not be null");
            //---------------Execute Test ----------------------
            string actualToString = dmInheritanceRelationship.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dmInheritanceRelationship.SubClass + "-" + dmInheritanceRelationship.SuperClass, actualToString);
        }

        [Test]
        public void Test_ToString_SuperClassNull()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            dmInheritanceRelationship.SuperClass = null;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmInheritanceRelationship.SubClass, "DMInheritanceRelationship.SubClass Should not be null");
            Assert.IsNull(dmInheritanceRelationship.SuperClass);
            //---------------Execute Test ----------------------
            string actualToString = dmInheritanceRelationship.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dmInheritanceRelationship.SubClass + "-", actualToString);
        }

        [Test]
        public void Test_ToString_SubClassNull()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            dmInheritanceRelationship.SubClass = null;
            //---------------Assert Precondition----------------
            Assert.IsNull(dmInheritanceRelationship.SubClass);
            Assert.IsNotNull(dmInheritanceRelationship.SuperClass);
            //---------------Execute Test ----------------------
            string actualToString = dmInheritanceRelationship.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual("-" + dmInheritanceRelationship.SuperClass, actualToString);
        }

        [Test]
        public void Test_ToString_SuperClassNull_SuperClassNull()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            dmInheritanceRelationship.SuperClass = null;
            dmInheritanceRelationship.SubClass = null;
            //---------------Assert Precondition----------------
            Assert.IsNull(dmInheritanceRelationship.SubClass);
            Assert.IsNull(dmInheritanceRelationship.SuperClass);
            //---------------Execute Test ----------------------
            string actualToString = dmInheritanceRelationship.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(dmInheritanceRelationship.ID.ToString(), actualToString);
        }
        [Test]
        public void Test_InsertNewSuperClassInfo()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = TestUtilsShared.CreateUnsavedValidDMInheritanceRelationship();

            //---------------Assert Precondition----------------
            Assert.IsTrue(dmInheritanceRelationship.Status.IsNew);

            //---------------Execute Test ----------------------
            dmInheritanceRelationship.Save();

            //---------------Test Result -----------------------
            Assert.IsFalse(dmInheritanceRelationship.Status.IsNew);
        }

        [Test]
        public void Test_InsertNewSuperClassInfo_Invalid()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();

            //---------------Assert Precondition----------------
            Assert.IsTrue(dmInheritanceRelationship.Status.IsNew);

            //---------------Execute Test ----------------------
            try
            {
                dmInheritanceRelationship.Save();
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (BusObjectInAnInvalidStateException ex)
            {
                StringAssert.Contains("Super Class' is a compulsory field and has no value.", ex.Message);
            }
            Assert.IsTrue(dmInheritanceRelationship.Status.IsNew);
        }

        [Test]
        public void Test_DeleteSuperClassInfo()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = TestUtilsShared.CreateSavedDMInheritanceRelationship();

            //---------------Assert Precondition----------------
            Assert.IsFalse(dmInheritanceRelationship.Status.IsNew);
            string message;
            Assert.IsTrue(dmInheritanceRelationship.IsDeletable(out message));

            //---------------Execute Test ----------------------
            dmInheritanceRelationship.MarkForDelete();
            dmInheritanceRelationship.Save();

            //---------------Test Result -----------------------  
            Assert.IsTrue(dmInheritanceRelationship.Status.IsNew);
            Assert.IsTrue(dmInheritanceRelationship.Status.IsDeleted);
        }

        [Test]
        public void Test_UpdateSuperClassInfo()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = TestUtilsShared.CreateSavedDMInheritanceRelationship();

            //---------------Assert Precondition----------------
            Assert.IsFalse(dmInheritanceRelationship.Status.IsNew);
            string message;
            Assert.IsTrue(dmInheritanceRelationship.IsEditable(out message));

            //---------------Execute Test ----------------------
            dmInheritanceRelationship.Generated = true;
            dmInheritanceRelationship.Save();

            //---------------Test Result -----------------------
            Assert.IsFalse(dmInheritanceRelationship.Status.IsNew);
        }

        [Test]
        public void Test_SingleTableInheritance_DiscriminatorCompulsory()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = TestUtilsShared.CreateUnsavedValidDMInheritanceRelationship();
            dmInheritanceRelationship.InheritanceType = ORMapping.SingleTableInheritance;
            //---------------Execute Test ----------------------
            try
            {
                dmInheritanceRelationship.Discriminator = null;
                dmInheritanceRelationship.Save();
                Assert.Fail("expected Err");
            }
            //---------------Test Result -----------------------
            catch (Exception ex)
            {
                StringAssert.Contains("The Discriminator is compulsory for Single Table Inheritance", ex.Message);
            }
            //---------------Tear Down -------------------------

        }

        [Test]
        public void Test_SingleTableInheritance()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.InheritanceType = ORMapping.SingleTableInheritance;
            TestUtilsShared.UpdateDMInheritanceRelationshipWithValidData(dmInheritanceRelationship);
            //------------Assert Preconditions--------------------
            Assert.AreEqual(ORMapping.SingleTableInheritance, dmInheritanceRelationship.InheritanceType);
            Assert.IsNotNull(dmInheritanceRelationship.Discriminator);
            //---------------Execute Test ----------------------

             dmInheritanceRelationship.Save();
            //---------------Test Result -----------------------
            Assert.IsFalse(dmInheritanceRelationship.Status.IsDirty);
        }

        [Test]
        public void Test_WhenDiscriminatorNotIdenticalForEntireHierachy_ShouldFail()
        {
            //---------------Set up test pack-------------------
            DMProperty parentDiscriminatorProp = TestUtilsShared.CreateSavedDMProperty();
            TestUtilsDMProperty.SetDMPropIntType(parentDiscriminatorProp);
            parentDiscriminatorProp.Save();

            DMInheritanceRelationship childParentRelationship = new DMInheritanceRelationship();
            IDMClass parentClass = parentDiscriminatorProp.Class;
            DMClass childClass = TestUtilsShared.CreateSavedDMClass(parentClass.Assembly);
            DMProperty childDiscriminatorProp = TestUtilsDMProperty.CreateUnsavedValidDMProperty(childClass);
            childParentRelationship.SubClass = childClass;
            childParentRelationship.SuperClass = (DMClass) parentClass;
            childParentRelationship.Discriminator = parentDiscriminatorProp.PropertyName;
            parentDiscriminatorProp.Compulsory = true;
            parentDiscriminatorProp.ReadWriteRule = PropReadWriteRule.WriteOnce;
            childClass.Save();
            childParentRelationship.Save();

            DMClass grandChildClass = TestUtilsShared.CreateSavedDMClass(parentClass.Assembly);
            DMInheritanceRelationship grandChildInheritanceRelationship = new DMInheritanceRelationship();
            grandChildInheritanceRelationship.SubClass = grandChildClass;
            grandChildInheritanceRelationship.SuperClass = childClass;
            grandChildInheritanceRelationship.Discriminator = childDiscriminatorProp.PropertyName;
            childDiscriminatorProp.Compulsory = true;
            childDiscriminatorProp.ReadWriteRule = PropReadWriteRule.WriteOnce;
            grandChildClass.Save();
            grandChildInheritanceRelationship.Save();

            //---------------Assert Precondition----------------
            Assert.AreNotEqual(grandChildInheritanceRelationship.Discriminator, childParentRelationship.Discriminator);
            //---------------Execute Test ----------------------
            IList<IBOError> errors;
            bool hasWarning = grandChildInheritanceRelationship.Status.HasWarnings(out errors);
            //---------------Test Result -----------------------
            Assert.IsTrue(hasWarning);
            Assert.AreEqual(1,errors.Count);

        }

        [Test]
        public void Test_WhenDiscriminatorIdenticalForEntireHierachy_ShouldPass()
        {
            //---------------Set up test pack-------------------
            DMProperty parentDiscriminatorProp = TestUtilsShared.CreateSavedDMProperty();
            TestUtilsDMProperty.SetDMPropIntType(parentDiscriminatorProp);
            parentDiscriminatorProp.Save();

            DMInheritanceRelationship childParentRelationship = new DMInheritanceRelationship();
            IDMClass parentClass = parentDiscriminatorProp.Class;
            DMClass childClass = TestUtilsShared.CreateSavedDMClass(parentClass.Assembly);
            childParentRelationship.SubClass = childClass;
            childParentRelationship.SuperClass = (DMClass) parentClass;
            childParentRelationship.Discriminator = parentDiscriminatorProp.PropertyName;
            parentDiscriminatorProp.Compulsory = true;
            parentDiscriminatorProp.ReadWriteRule = PropReadWriteRule.WriteOnce;
            childClass.Save();
            childParentRelationship.Save();

            DMClass grandChildClass = TestUtilsShared.CreateSavedDMClass(parentClass.Assembly);
            DMInheritanceRelationship grandChildInheritanceRelationship = new DMInheritanceRelationship
            {
                SubClass = grandChildClass,
                SuperClass = childClass
            };
            grandChildInheritanceRelationship.Discriminator = parentDiscriminatorProp.PropertyName;
            parentDiscriminatorProp.Compulsory = true;
            parentDiscriminatorProp.ReadWriteRule = PropReadWriteRule.WriteOnce;
            grandChildClass.Save();
            grandChildInheritanceRelationship.Save();

            //---------------Assert Precondition----------------
            Assert.AreEqual(grandChildInheritanceRelationship.Discriminator, childParentRelationship.Discriminator);
            //---------------Execute Test ----------------------
            IList<IBOError> errors;
            bool hasWarning = grandChildInheritanceRelationship.Status.HasWarnings(out errors);
            //---------------Test Result -----------------------
            Assert.IsFalse(hasWarning);
            Assert.AreEqual(0,errors.Count);
        }

        [Test]
        public void Test_SuperClassPropertyFindsSuperClassFromClassName_WhenSuperClassNotSetButInDMSolution()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            DMClass originalSuperClass = dmInheritanceRelationship.SuperClass;
            string className = dmInheritanceRelationship.SuperClass.ClassNameBO;
            string assemblyName = dmInheritanceRelationship.SuperClass.Assembly.AssemblyName;
            dmInheritanceRelationship.SuperClass = null;
            ISuperClassDef superClassDef = dmInheritanceRelationship;
            superClassDef.ClassName = className;
            superClassDef.AssemblyName = assemblyName;
            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            DMClass superClass = dmInheritanceRelationship.SuperClass;
            //---------------Test Result -----------------------
            Assert.IsNotNull(superClass);
            Assert.AreSame(originalSuperClass, superClass);
            //---------------Tear Down -------------------------          
        }

        [Test]
        public void Test_SuperClassPropertyFindsSuperClassFromClassName_WhenSuperClassNotSetButInClassDefCol()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            dmInheritanceRelationship.SuperClass = TestUtilsShared.CreateUnsavedValidDMClass();
            DMClass originalSuperClass = dmInheritanceRelationship.SuperClass;
            ClassDefCol.GetColClassDef().Add(originalSuperClass);
            string className = dmInheritanceRelationship.SuperClass.ClassNameBO;
            string assemblyName = dmInheritanceRelationship.SuperClass.Assembly.AssemblyName;
            dmInheritanceRelationship.SuperClass = null;
            ISuperClassDef superClassDef = dmInheritanceRelationship;
            superClassDef.ClassName = className;
            superClassDef.AssemblyName = assemblyName;
            //---------------Assert PreConditions---------------            
            //---------------Execute Test ----------------------
            DMClass superClass = dmInheritanceRelationship.SuperClass;
            //---------------Test Result -----------------------
            Assert.IsNotNull(superClass);
            Assert.AreSame(originalSuperClass, superClass);
            //---------------Tear Down -------------------------          
        }

        [Test]
        public void Test_SetSuperClassID_SetsSuperClassRelationship()
        {
            //---------------Set up test pack------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMInheritanceRelationship relationship = new DMInheritanceRelationship();
            //--------------Assert Preconditions------------------
            Assert.IsNull(relationship.SuperClass);
            Assert.AreEqual(0, dmClass.SubClassRelationships.Count);
            //-----------------Execute Test-----------------------
            relationship.SuperClassID = dmClass.ClassID;
            //---------------Test Result -----------------------          
            Assert.IsNotNull(relationship.SuperClass);
            Assert.AreSame(dmClass, relationship.SuperClass);
            Assert.AreEqual(1, dmClass.SubClassRelationships.Count);
        }

        [Test]
        public void Test_CreateDiscriminator_WhenSuperClassNotSet_ShouldThrowAnError()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMInheritanceRelationship relationship = new DMInheritanceRelationship();
            relationship.SubClass = dmClass;
            //--------------Assert Preconditions------------------
            Assert.IsNull(relationship.SuperClass);
            Assert.IsNotNull(relationship.SubClass);
            //---------------Execute Test ----------------------
            try
            {
                relationship.CreateDiscriminator();
                Assert.Fail("Expected to throw an UserException");
            }
                //---------------Test Result -----------------------
            catch (UserException ex)
            {
                StringAssert.Contains("The Super Class has not been set", ex.Message);
            }
        }
        [Test]
        public void Test_CreateDiscriminator_WhenSubClassNotSet_ShouldThrowAnError()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMInheritanceRelationship relationship = new DMInheritanceRelationship {SuperClass = dmClass};
            //--------------Assert Preconditions------------------
            Assert.IsNotNull(relationship.SuperClass);
            Assert.IsNull(relationship.SubClass);
            //---------------Execute Test ----------------------
            try
            {
                relationship.CreateDiscriminator();
                Assert.Fail("Expected to throw an UserException");
            }
                //---------------Test Result -----------------------
            catch (UserException ex)
            {
                StringAssert.Contains("The Sub Class has not been set", ex.Message);
            }
        }

        [Test]
        public void Test_CreateDiscriminator_WhenSuperClassIsSet_ShouldCreateABOProp()
        {
            //this.InheritanceSuperClassRelationship.InheritanceType == ORMapping.SingleTableInheritance
            //Create new Property on SuperClass.
            //SetPropertyName = SuperClass.ClassNameBO + "Type"
            //                this.InheritanceSuperClassRelationship.Discriminator = newProperty.PropertyName;
            //---------------Set up test pack-------------------
            DMInheritanceRelationship relationship = TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            relationship.Discriminator = "";
            DMClass superClass = relationship.SuperClass;
            int initialPropCount = superClass.Properties.Count;
            //--------------Assert Preconditions------------------
            Assert.IsNotNull(superClass);
            Assert.IsNotNull(relationship.SubClass);
            Assert.IsTrue(string.IsNullOrEmpty(relationship.Discriminator), "Desc should not be set before createRelationship");
            //---------------Execute Test ----------------------
            relationship.CreateDiscriminator();
            //---------------Test Result ----------------------- 
            Assert.AreEqual(initialPropCount+1,superClass.Properties.Count);
            string expectedDiscriminatorName = superClass.ClassNameBO + "Type";
            IDMProperty property = superClass.GetDMProperty(expectedDiscriminatorName);
            Assert.IsNotNull(property, "Discriminator property should be created");
            Assert.AreEqual(expectedDiscriminatorName,relationship.Discriminator);
        }

        [Test]
        public void Test_CreateDiscriminator_WhenConcreteTableInheritance_ShouldThrowAnError()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship relationship = TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            DMClass superClass = relationship.SuperClass;
            relationship.InheritanceType = ORMapping.ConcreteTableInheritance;
            
            //--------------Assert Preconditions------------------
            Assert.IsNotNull(superClass);
            Assert.IsNotNull(relationship.SubClass);
            Assert.AreEqual(relationship.InheritanceType,ORMapping.ConcreteTableInheritance);
            //---------------Execute Test ----------------------
            try
            {
                relationship.CreateDiscriminator();
                Assert.Fail("Expected to throw a UserException");
            }
                //---------------Test Result -----------------------
            catch (UserException ex)
            {
                StringAssert.Contains("The Inheritance Type cannot be Concrete Table Inheritance", ex.Message);
            }
        }

        [Test]
        public void Test_GetIDLookupList_WhenSubClassNull_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMInheritanceRelationship relationship = new DMInheritanceRelationship {SuperClass = dmClass};
            //--------------Assert Preconditions------------------
            Assert.IsNull(relationship.SubClass);
            Assert.IsNotNull(relationship.SuperClass);
            //---------------Execute Test ----------------------
            var idLookupList = relationship.GetIDLookupList();
            //---------------Test Result -----------------------
            Assert.IsNull(idLookupList);
        }
        
        [Test]
        public void Test_GetIDLookupList_WhenSuperClassNull_ShouldReturnNull()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClass();
            DMInheritanceRelationship relationship = new DMInheritanceRelationship();
            relationship.SubClass = dmClass;
            //--------------Assert Preconditions------------------
            Assert.IsNull(relationship.SuperClass);
            Assert.IsNotNull(relationship.SubClass);
            //---------------Execute Test ----------------------
            var idLookupList = relationship.GetIDLookupList();
            //---------------Test Result -----------------------
            Assert.IsNull(idLookupList);
        } 
        
        [Test]
        public void Test_GetIDLookupList_WhenSuperClassHasCompositeKey_ShouldThrowAnError()
        {
            //---------------Set up test pack-------------------
            DMClass superClassWithCompositeID = TestUtilsDMClass.CreateSavedDMClassWithCompositeOID(2);
            DMInheritanceRelationship relationship = TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            relationship.SuperClass = superClassWithCompositeID;
            //--------------Assert Preconditions------------------
            Assert.AreEqual(2,superClassWithCompositeID.Properties.Count);
            Assert.AreEqual(2,superClassWithCompositeID.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            try
            {
                var idLookupList = relationship.GetIDLookupList();
                Assert.Fail("Expected to throw an UserException");
            }
                //---------------Test Result -----------------------
            catch (UserException ex)
            {
                StringAssert.Contains("You cannot use a DMClass that has a Composite Primary Key in an Inheritance Relationship", ex.Message);
            }
           
        }
        
        [Test]
        public void Test_GetIDLookupList_WhenSubClassHasCompositeKey_ShouldThrowAnError()
        {
            //---------------Set up test pack-------------------
            DMClass subClassWithCompositeID = TestUtilsDMClass.CreateSavedDMClassWithCompositeOID(2);
            DMInheritanceRelationship relationship = TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            relationship.SubClass = subClassWithCompositeID;
            //--------------Assert Preconditions------------------
            Assert.AreEqual(2,subClassWithCompositeID.Properties.Count);
            Assert.AreEqual(2,subClassWithCompositeID.ObjectIdentity.Properties.Count);
            //---------------Execute Test ----------------------
            try
            {
                var idLookupList = relationship.GetIDLookupList();
                Assert.Fail("Expected to throw an UserException");
            }
                //---------------Test Result -----------------------
            catch (UserException ex)
            {
                StringAssert.Contains("You cannot use a DMClass that has a Composite Primary Key in an Inheritance Relationship", ex.Message);
            }
        }

        [Test]
        public void Test_GetIDLookupList_WhenSuperClassObjectIDIsNull_ShouldReturnEmpty()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship relationship = TestUtilsDMInheritanceRelationship.CreateUnsavedValidDMInheritanceRelationship();
            DMClass superClass = relationship.SuperClass;
            DMObjectIdentity superClassObjectID = superClass.GetObjectID();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(superClass);
            Assert.IsNull(superClassObjectID);
            //---------------Execute Test ----------------------
            var idLookupList = relationship.GetIDLookupList();
            //---------------Test Result -----------------------
            Assert.IsEmpty(idLookupList);
        }

        [Test]
        public void Test_GetIDLookupList_WhenSuperClassExistsWithSingleID_ShouldSetUpComboBoxWithAllProps()
        {
            //---------------Set up test pack-------------------
            DMClass subClass = TestUtilsDMClass.CreateSavedDMClassWithNoOID(2);
            DMClass superClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);

            DMInheritanceRelationship relationship = TestUtilsShared.CreateUnsavedValidDMInheritanceRelationship();
            relationship.SubClass = subClass;
            relationship.SuperClass = superClass;
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, superClass.ObjectIdentity.Properties.Count);
            Assert.AreEqual(2, superClass.Properties.Count);
            Assert.AreEqual(2, subClass.Properties.Count);
            //---------------Execute Test ----------------------
            var idLookupList = relationship.GetIDLookupList();
            //---------------Test Result -----------------------
            Assert.AreEqual(3,idLookupList.Count , "The two props, plus SuperClassID Prop");
        }
        [Test]
        public void Test_GetIDLookupList_WhenSuperClassExistsWithSingleID_AndSubClassHasPropWithSameID_ShouldSetUpComboBoxWithAllProps_FIXBUG871()
        {
            //---------------Set up test pack-------------------
            DMClass subClass = TestUtilsDMClass.CreateSavedDMClassWithNoOID(2);
            DMClass superClass = TestUtilsDMClass.CreateSavedDMClassWithOID(1);
            DMProperty boProp = subClass.Properties.CreateBusinessObject();
            boProp.PropertyName = superClass.ObjectIdentity.Properties[0].PropertyName;
            DMInheritanceRelationship relationship = TestUtilsShared.CreateUnsavedValidDMInheritanceRelationship();
            relationship.SubClass = subClass;
            relationship.SuperClass = superClass;
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, superClass.ObjectIdentity.Properties.Count);
            Assert.AreEqual(2, superClass.Properties.Count);
            Assert.AreEqual(3, subClass.Properties.Count);
            //---------------Execute Test ----------------------
            var idLookupList = relationship.GetIDLookupList();
            //---------------Test Result -----------------------
            Assert.AreEqual(3,idLookupList.Count , "The two props, plus SuperClassID Prop");
        }

        [Test]
        public void Test_GetDiscriminatorProp()
        {
            //---------------Set up test pack-------------------
            var dmInheritanceRelationship = TestUtilsShared.CreateUnsavedValidDMInheritanceRelationship();
            var superClass = dmInheritanceRelationship.SuperClass;
            var property = superClass.CreateDMProp();
            const string name = "Discriminator";
            property.PropertyName = name;
            superClass.Properties.Add(property);
            dmInheritanceRelationship.Discriminator = name;
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            IDMProperty discrimProperty = dmInheritanceRelationship.GetDiscriminatorProp();
            //---------------Test Result -----------------------
            Assert.AreEqual(property, discrimProperty);           
        }

        [Test]
        public void Test_SubClassName_WhenSubClassIsNull_ShouldReturnEmptyString()
        {
            //---------------Set up test pack-------------------
            var dmInheritanceRelationship = TestUtilsDMInheritanceRelationship.CreateUnsavedDefaultDMInheritanceRelationship();
            //---------------Assert Precondition----------------
            Assert.IsNull(dmInheritanceRelationship.SubClass);
            //---------------Execute Test ----------------------
            var subClassName = dmInheritanceRelationship.SubClassName;
            //---------------Test Result -----------------------
            Assert.IsNullOrEmpty(subClassName);
        }
        [Test]
        public void Test_SubClassName_WhenSubClassIsNotNull_ShouldReturnSubClassName()
        {
            //---------------Set up test pack-------------------
            var subClass = TestUtilsDMClass.GetFactory().WithOutSingleRelationships().CreateValidBusinessObject();
            var dmInheritanceRelationship = TestUtilsDMInheritanceRelationship.GetFactory()
                    .WithValue(relationship => relationship.SubClass, subClass)
                    .WithOutSingleRelationships()
                    .CreateValidBusinessObject();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmInheritanceRelationship.SubClass);
            Assert.AreSame(subClass, dmInheritanceRelationship.SubClass);
            Assert.IsNotNullOrEmpty(subClass.ClassNameBO);
            //---------------Execute Test ----------------------
            var subClassName = dmInheritanceRelationship.SubClassName;
            //---------------Test Result -----------------------
            Assert.AreEqual(subClass.ClassNameBO, subClassName);
        }


        [Test]
        public void Test_DMInheritanceRelationshipRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            var inheritanceRelationship = new DMInheritanceRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(inheritanceRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMInheritanceRelationshipDiscriminatorMustBeStringProp>(rules);
        }
        [Test]
        public void Test_DMInheritanceHierachyDiscriminatorsAreEqualRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            var inheritanceRelationship = new DMInheritanceRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(inheritanceRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMInheritanceHierachyDiscriminatorsAreEqual>(rules);
        }

        [Ignore("Release for Version Habanero 2.5.1")] //TODO Brett 21 Nov 2010: Ignored Test - Release for Version Habanero 2.5.1 which does not set the descriminator value.
        [Test]
        public void Test_DMInheritanceRelationshipDiscriminatorMustBeCompulsoryAndWriteOnceOrWriteNewRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            var inheritanceRelationship = new DMInheritanceRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(inheritanceRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMInheritanceRelationshipDiscriminatorMustBeCompulsoryAndWriteOnceOrWriteNew>(rules);
        }

        [Test]
        public void Test_DMSingleTableInheritanceSubClassShouldNotHaveObjectIdentityRule_ShouldBeOnBusinessObject()
        {
            //---------------Set up test pack-------------------
            var inheritanceRelationship = new DMInheritanceRelationship();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            ReadOnlyCollection<IBusinessObjectRule> rules = BOHelper.GetBusinessObjectRules(inheritanceRelationship);
            //---------------Test Result -----------------------
            TestUtilsShared.AssertHasRuleOfType<DMSingleTableInheritanceSubClassShouldNotHaveObjectIdentity>(rules);
        }
    }
}